import { assert, AudioSource, Component, game, _decorator } from 'cc';
const { ccclass, property } = _decorator;
import { AudioManager } from './AudioManager';

@ccclass('GameRoot')
export class GameRoot extends Component {

    @property(AudioSource)
    _audioSource: AudioSource = null!;

    onLoad() {
        console.log('音频测试')
        const audioSource = this.node.getComponent(AudioSource);
        assert(audioSource);
        this._audioSource = audioSource;
        // 声明常驻根节点，该节点不会在场景切换中被销毁。目标节点必须是根节点，否则无效。
        game.addPersistRootNode(this.node);


        // 将节点封装到管理器中
        AudioManager.instance.init(this._audioSource);
    }
}
